<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useMainStore } from './store/index'
import * as echarts from 'echarts' //引入echarts
import './assets/China.js' //引入地图文件
import { geoCoordMap } from './assets/geoMap'
import 'animate.css'
const MainStore = useMainStore();
onMounted(async () => {
  await MainStore.getList()
  initCharts()
  initPie()
  initLine()
})
// 初始化表格数据
const initCharts = () => {
  const city = MainStore.list.diseaseh5Shelf.areaTree[0].children
  MainStore.item = city[1].children as []
  console.log(MainStore.list);
  const charts = echarts.init(document.querySelector('#China') as HTMLElement)
  const data = city.map(item => {
    return {
      name: item.name,
      value: geoCoordMap[item.name].concat(item.total.nowConfirm),
      children: item.children
    }
  })
  charts.setOption({
    geo: {
      map: "china",
      aspectScale: 0.8,
      layoutCenter: ["50%", "50%"],
      layoutSize: "100%",
      itemStyle: {
        //  normal: {
        areaColor: {
          type: "linear-gradient",
          x: 0,
          y: 1200,
          x2: 1000,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: "#152E6E", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "#0673AD", // 50% 处的颜色
            },
          ],
          global: true, // 缺省为 false
        },
        shadowColor: "#0f5d9d",
        shadowOffsetX: 0,
        shadowOffsetY: 15,
        opacity: 0.5,
        // },

      },
      emphasis: {
        areaColor: "#0f5d9d",
      },

      regions: [
        {
          name: "南海诸岛",
          itemStyle: {
            areaColor: "rgba(0, 10, 52, 1)",
            borderColor: "rgba(0, 10, 52, 1)",
            //normal: {
            opacity: 0,
            label: {
              show: false,
              color: "#009cc9",
            },
            //},
          },
          label: {
            show: false,
            color: "#FFFFFF",
            fontSize: 12,
          },
        },
      ],
    },
    series: [
      {
        type: "map",
        map: "china",
        aspectScale: 0.8,
        layoutCenter: ["50%", "50%"], //地图位置
        layoutSize: "100%",
        label: {
          show: true,
          color: "#FFFFFF",
          fontSize: 12,
        },
        itemStyle: {
          areaColor: "#0c3653",
          borderColor: "#1cccff",
          borderWidth: 1.8,
        },
        emphasis: {
          areaColor: "#56b1da",
          label: {
            show: true,
            color: "#fff",
          },
        },
        data: data,
      },
      {
        type: 'scatter',
        coordinateSystem: 'geo',
        symbol: 'pin',
        symbolSize: [45, 45],
        label: {
          show: true,
          color: "#fff",
          formatter(value: any) {
            return value.data.value[2]
          }
        },
        itemStyle: {
          color: '#1E90FF', //标志颜色
        },
        data: data,
      },
    ],
  }) //地图配置
  charts.on('click', (value: any) => {
    MainStore.item = value.data.children
    console.log(value.data.children);
  })
}
// 初始化饼图数据
const initPie = () => {
  const charts = echarts.init(document.querySelector('.box-left-pie') as HTMLElement)
  console.log(MainStore.cityDetail);
  const city = MainStore.cityDetail
  const data = city.map(item => {
    return {
      value: item.nowConfirm,
      name: item.city
    }
  })
  charts.setOption({
    backgroundColor: "#223651",
    tooltip: {
      trigger: 'item'
    },
    // legend: {
    //   top: '5%',
    //   left: 'center'
    // },
    series: [
      {
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: true,
        itemStyle: {
          borderRadius: 4,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: true,
          // position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: '15',
            fontWeight: 'bold'
          }
        },
        data: data
      }
    ]
  })
}

// 初始化折线数据

const initLine = () => {
  const charts = echarts.init(document.querySelector('.box-left-line') as HTMLElement)
  charts.setOption({
    backgroundColor: "#223651",
    tooltip: {
      trigger: 'item'
    },
    xAxis: {
      type: 'category',
      data: MainStore.cityDetail.map(item => {
        return item.city
      }),
      axisLine: {
        lineStyle: {
          color: "#6E7079",
          width: 1,
          type: "solid"
        }
      }
    },
    yAxis: {
      type: 'value',
      axisLine: {
        lineStyle: {
          color: "#6E7079",
          width: 1,
          type: "solid"
        }
      }
    },
    label: {
      show: true
    },
    series: [
      {
        data: MainStore.cityDetail.map(item => {
          return item.confirm
        }),
        type: 'line'
      }
    ]
  }
  )
}
</script>

<template>
  <div class="box">
    <div class="box-left" style="color:white">
      <div class="box-left-list">
        <div class="item">
          <div>较上日+{{ MainStore.chinaAdd.localConfirmH5 }}</div>
          <div>{{ MainStore.chinaTotal.localConfirm }}</div>
          <div>本土现有确诊</div>
        </div>
        <div class="item">
          <div>较上日+{{ MainStore.chinaAdd.nowConfirm }}</div>
          <div>{{ MainStore.chinaTotal.nowConfirm }}</div>
          <div>现有确诊</div>
        </div>
        <div class="item">
          <div>较上日+{{ MainStore.chinaAdd.confirm }}</div>
          <div>{{ MainStore.chinaTotal.confirm }}</div>
          <div>累计确认</div>
        </div>
        <div class="item">
          <div>较上日+{{ MainStore.chinaAdd.noInfect }}</div>
          <div>{{ MainStore.chinaTotal.noInfect }}</div>
          <div>无症状感染者</div>
        </div>
        <div class="item">
          <div>较上日+{{ MainStore.chinaAdd.importedCase }}</div>
          <div>{{ MainStore.chinaTotal.importedCase }}</div>
          <div>境外输入</div>
        </div>
        <div class="item">
          <div>较上日+{{ MainStore.chinaAdd.dead }}</div>
          <div>{{ MainStore.chinaTotal.dead }}</div>
          <div>累计死亡</div>
        </div>
      </div>
      <div class="box-left-pie"></div>
      <div class="box-left-line"></div>
    </div>
    <div class="box-center" id="China">
    </div>
    <div class="box-right" style="color:white ">
      <table border="1" cellspacing="0">
        <thead>
          <tr>
            <th>地区</th>
            <th>新增确诊</th>
            <th>累计确诊</th>
            <th>治愈</th>
            <th>死亡</th>
          </tr>
        </thead>
        <transition-group enter-active-class="animate__animated animate__fadeInLeft" tag="tbody">
          <tr :key="item.date" v-for="item in MainStore.item">
            <td>{{ item.name }}</td>
            <td>{{ item.today.confirm }}</td>
            <td>{{ item.total.confirm }}</td>
            <td>{{ item.total.heal }}</td>
            <td>{{ item.total.dead }}</td>
          </tr>
        </transition-group>
      </table>
    </div>
  </div>

</template>

<style lang="less">
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

@itemColor: #41b0db;
@itemBg: #223651;
@itemBorder: #212028;

html,
body,
#app {
  height: 100%;
  overflow: hidden;
}

.box {
  display: flex;
  overflow: hidden;
  height: 100%;
  background: url('./assets/bg.png');

  &-left {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 400px;
    flex: 0 0 400px;

    &-list {
      display: flex;
      flex-wrap: wrap;
      background-color: @itemBg;

      .item {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        width: 33%;
        height: 100px;
        //  padding: 5px;
        border: 1px solid @itemBorder;

        //  text-align: center;
        div:nth-child(2) {
          color: @itemColor;
          font-weight: 600;
        }
      }
    }

    &-pie {
      // width: 100%;
      height: 320px;
      // margin-top: 20px;
    }

    &-line {
      height: 320px;
      // margin-top: 20px;
    }
  }

  &-center {
    flex: 1;
    // background-color: #008c8c;
  }

  &-right {
    width: 400px;
    flex: 0 0 400px;

    table {
      width: 100%;
      background-color: #212028;

      th,
      td {
        text-align: center;
        padding: 5px;
      }
    }
  }
}
</style>
